<template>
  <div class="device-data">
    <tab-bar :list="tabList" @change="tabSwitch" />
    <div class="device-content">
      <keep-alive>
        <component :is="tabList.find(item => item.key === active).compName"></component>
      </keep-alive>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import * as api from '@/api'
import compList from '@/consts/componentMaps'
import tabBar from '@/components/tabBar'
import tempMonitor from '@/components/tempMonitor'
import humMonitor from '@/components/humMonitor'
import salesStatistics from '@/components/salesStatistics'
import productionRecord from '@/components/productionRecord'
import clearningTime from '@/components/clearningTime'
import extractionTime from '@/components/extractionTime'
import alarmRecord from '@/components/alarmRecord'
export default {
  components: {
    tabBar,
    tempMonitor,
    humMonitor,
    salesStatistics,
    productionRecord,
    clearningTime,
    extractionTime,
    alarmRecord
  },
  props: {
    tabList: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      active: '1'
    }
  },
  computed: {
    ...mapState(['deviceDetail'])
  },
  methods: {
    tabSwitch(v) {
      this.active = v
      const { dashtype } = this.tabList.find(item => item.key === v)
      this.$store.commit('setState', {
        name: 'dashtype',
        value: dashtype
      })
    },
  },
  created () {
    this.tabSwitch('1')
  },
}
</script>

<style lang="stylus">
.device-data {
  padding-top: getPx(20);
  box-sizing:border-box;
  .device-content {
    margin-top: getPx(10);
    overflow: hidden
  }
}
</style>